# 输入
# 100 10
# 95 96 97 98 99 101 102 103 104 105
# 输出
# 99 101 98 102 97 103 96 104 95 105
import functools


def cmp(a, b):
    if abs(int(a) - h) - abs(int(b) - h) > 0:
        return 1
    elif abs(int(a) - h) == abs(int(b) - h):
        if a > b:
            return -1
        else:
            return 1
    else:
        return -1


list_1 = input().split(" ")
h = int(list_1[0])
n = int(list_1[1])
list_2 = input().split(" ")
#print(list_2)
list_3 = sorted(list_2, key=functools.cmp_to_key(cmp))
print(" ".join(list_3))
